package com.songhuan.web.controller;

import com.songhuan.web.dto.*;
import com.songhuan.web.dto.query.*;
import com.songhuan.web.entity.*;
import com.songhuan.web.mapper.*;
import com.songhuan.web.service.*;
import com.songhuan.web.tools.dto.*;
import com.songhuan.web.dto.CheckSettingDto;
import com.songhuan.web.dto.query.CheckSettingPagedInput;
import com.songhuan.web.mapper.CheckSettingMapper;
import com.songhuan.web.service.CheckSettingService;
import com.songhuan.web.tools.dto.IdInput;
import com.songhuan.web.tools.dto.IdsInput;
import com.songhuan.web.tools.dto.PagedResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.SneakyThrows;

import java.util.List;

/**
 * 考勤设置控制器
 */
@RestController
@RequestMapping("/CheckSetting")
public class CheckSettingController {

    @Autowired
    private CheckSettingService _CheckSettingService;

    /**
     * 考勤设置分页查询
     */
    @RequestMapping(value = "/List", method = RequestMethod.POST)
    @SneakyThrows
    public PagedResult<CheckSettingDto> List(@RequestBody CheckSettingPagedInput input) {
        return _CheckSettingService.List(input);
    }

    /**
     * 单个考勤设置查询接口
     */
    @RequestMapping(value = "/Get", method = RequestMethod.POST)
    @SneakyThrows
    public CheckSettingDto Get(@RequestBody CheckSettingPagedInput input) {

        return _CheckSettingService.Get(input);
    }

    /**
     * 考勤设置创建或则修改
     */
    @RequestMapping(value = "/CreateOrEdit", method = RequestMethod.POST)
    public CheckSettingDto CreateOrEdit(@RequestBody CheckSettingDto input) throws Exception {
        return _CheckSettingService.CreateOrEdit(input);
    }

    /**
     * 考勤设置删除
     */
    @RequestMapping(value = "/Delete", method = RequestMethod.POST)
    public void Delete(@RequestBody IdInput input) {
        _CheckSettingService.removeById(input.getId());
    }

    /**
     * 考勤设置批量删除
     */
    @RequestMapping(value = "/BatchDelete", method = RequestMethod.POST)
    public void BatchDelete(@RequestBody IdsInput input) {
        _CheckSettingService.removeByIds(input.getIds());
    }

    /**
     * 根据请假时间拉取考勤课程列表
     */
    @RequestMapping(value = "/GetCheckCourseList", method = RequestMethod.POST)
    public ResponseData<List<CheckSetting>> GetCheckCourseList(@RequestBody CheckSettingDto input) {

        List<CheckSetting> checkSettings = _CheckSettingService.GetCheckCourseList(input);
        return ResponseData.GetResponseDataInstance(checkSettings, "获取成功", true);
    }

    /**
     * 下拉框
     */
    @RequestMapping(value = "/GetSelectList", method = RequestMethod.POST)
    public ResponseData<List<CheckSetting>> GetSelectList() {

        List<CheckSetting> selectListDtos = _CheckSettingService.GetSelectList();
        return ResponseData.GetResponseDataInstance(selectListDtos, "获取成功", true);
    }

    /**
     * 获取单个考勤结果
     */
    @RequestMapping(value = "/GetOne", method = RequestMethod.POST)
    public ResponseData<CheckSetting> GetOne(@RequestBody IdInput input) {

        CheckSetting checkSetting = _CheckSettingService.getById(input.getId());
        return ResponseData.GetResponseDataInstance(checkSetting, "获取成功", true);
    }

}
